package com.bykj.taketurns.fragment;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bykj.taketurns.activity.BaseActivity;
import com.bykj.taketurns.application.MyApplication;

/**
 * Created by Administrator on 2017/8/13.
 */

public abstract class BaseFragment extends Fragment implements View.OnClickListener{
    public BaseActivity activity;
    //初始化视图
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return getRootView();
    }
    protected  abstract View getRootView();
    //绑定activity
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity= (BaseActivity) context;
    }

    @Override
    public void onResume() {
        super.onResume();
        postData();
    }

    @Override
    public void onStart() {
        super.onStart();


    }
    //创建视图
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view,savedInstanceState);

    }
    //初始化视图
    protected abstract void initView(View view,Bundle savedInstanceState);
    //加载数据
    protected abstract void postData();
    //加载网络数据
    protected abstract void initData();
    //获取状态栏高度
    public static int getStatusBarHeight(Activity a) {
        int result = 0;
        int resourceId = a.getResources().getIdentifier("status_bar_height",
                "dimen", "android");
        if (resourceId > 0) {
            result = a.getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        MyApplication.getRefWatcher(getActivity()).watch(this);
    }
}
